<template>
  <t-import-export
    ref="imEx"
    :import="handleImport"
    :getImportFile="getImportFile"
    :retryJson="retryJson"
    :uplaodFile="uplaodFile"
    v-model:sheetName="sheetName"
    :sheetList="sheetList"
    :export="handleExport"
    :downloadStencil="downloadStencil"
    :handleMissionList="handleMissionList"
    :pageIndex="pageIndex"
    :pageSize="pageSize"
    :rowsIm="rowsIm"
    :downloadExcel="downloadExcel"
    :deleteLine="deleteLine"
    :tautology="tautology"
    v-model:dialogEx="dialogEx"
    v-model:dialog="dialog"
    v-model:tab="tab"
    v-model:dialogSheet="dialogVisibleTip"
  ></t-import-export>
  <br />

  <div class="q-pa-md q-gutter-sm" @click="handleFather">father 测试方法</div>
</template>

<script setup>
  import { nextTick, reactive, ref } from 'vue'; // nextTick
  // data
  //
  // window.ResourcePath => window.TeldWebConfig.ResourceURL
  const dialog = ref(true);
  const dialogEx = ref(false);
  const tab = ref(0);
  const imEx = ref(null);
  const retryJson = ref(undefined);
  const uplaodFile = ref(true);
  const uploadUrl = ref('');
  const uploadName = ref('');
  const sheetName = ref(''); // ref('sheet0');
  const sheetList = reactive([]); // reactive([{ label: 'sheet0', value: 'sheet0' }]);
  const dialogVisibleTip = ref(false);
  const totalNum = ref(0);
  const totalPage = ref(0);
  const pageIndex = ref(1);
  const pageSize = ref(0);
  const totalCount = ref(0);

  // 任务列表 - 导入任务 - table 数据
  // const rowsIm = reactive([]);
  // flag 模拟数据
  const rowsIm = reactive([
    {
      ID: '001',
      State: 1,
      FileName: 'Frozen Yogurt',
      ElapsedSeconds: 4.0,
      SuccessCount: 87,
      FailedCount: 33,
      failReason: '1%',
    },
    {
      ID: '002',
      State: 2,
      FileName: 'Frozen Yogurt',
      ElapsedSeconds: 4.0,
      SuccessCount: 87,
      FailedCount: 33,
      failReason: '1%',
    },
    {
      ID: '002',
      State: 3,
      FileName: 'Frozen Yogurt',
      ElapsedSeconds: 4.0,
      SuccessCount: 87,
      FailedCount: 33,
      failReason: '1%',
    },
  ]);
  const stringImportConfig = `{
      "ID": "dec6e0fc-9a1f-f568-d0d7-6aee4af49ad5",
      "Code": "ImportConfig",
      "Name": "导入高级设置",
      "IsReadOnly": false,
      "IsEnum": false,
      "IsRef": true,
      "IsInternational": true,
      "NeedSpecialTreatment": true,
      "ValueType": "String",
      "Description": "导入高级设置",
      "PropertyEditor": {
        "PropertyEditorType": 25,
        "ConfigJSON": {
          "columnsDefine": {
            "ColName": {
              "noedit": true,
              "Type": "String",
              "mockValue": "CDO字段"
            },
            "ImportRules": {
              "Type": "colSummaryType",
              "mockValue": "导入规则",
              "dsColSummaryType": [
                {
                  "value": 0,
                  "text": "导入"
                },
                {
                  "value": 1,
                  "text": "忽略"
                },
                {
                  "value": 2,
                  "text": "系统生成"
                }
              ]
            },
            "isShow": {
              "Type": "Bool",
              "DefaultValue": false,
              "mockValue": "是否导入"
            },
            "ExcelColName": {
              "noedit": false,
              "Type": "String",
              "mockValue": "Excel列名"
            },
            "IsRequired": {
              "Type": "Bool",
              "DefaultValue": false,
              "mockValue": "是否必填"
            },
            "IsUnique": {
              "Type": "Bool",
              "DefaultValue": false,
              "mockValue": "重复性检查"
            },
            "Script": {
              "Type": "String",
              "mockValue": "规则定义",
              "noedit": false
            },
            "Explain": {
              "noedit": false,
              "Type": "String",
              "mockValue": "填写说明"
            },
            "IsHelp": {
              "Type": "Bool",
              "DefaultValue": false,
              "mockValue": "启用帮助"
            },
            "DataSource": {
              "Type": "colLinkFormat",
              "mockValue": "选择帮助"
            },
            "DisplayField": {
              "noedit": false,
              "Type": "String",
              "mockValue": "帮助显示字段"
            },
            "ValueField": {
              "noedit": false,
              "Type": "String",
              "mockValue": "帮助值字段"
            }
          }
        },
        "Extends": {}
      },
      "DefaultValue": "",
      "IsRequired": false,
      "PropType": 1,
      "Level": 0,
      "ParentID": "",
      "ShowValue": "",
      "MappingName_PC": "importConfig",
      "MappingName_Mobile": "importConfig",
      "IsNative": true,
      "FasDefaultValue": "",
      "Value": "",
      "DisplayName": "",
      "hide": false,
      "CdoSource": {
        "Value": {
          "ID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
          "Code": "CDO_DO_export_zhangbao1",
          "Name": "CDO_数据对象144933",
          "ParentID": "23046344-a8ef-4c3e-b41d-b82d33cee408",
          "TypeID": "",
          "Layer": 0,
          "IsDetail": false,
          "SortCode": 1,
          "Icon": "icon-fascdo cdo",
          "TreeItemID": "CDO",
          "DataResultType": "",
          "MetaDataType": null,
          "seqNum": "1.1",
          "ActionType": 4,
          "Children": [
            {
              "ID": "a75fd07f-2ed3-4fb4-a9cb-5d1c7dd4a2de",
              "Code": "BatchCreateCDO_DO_export_zhangbao1",
              "Name": "批量新增CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Void",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.1"
            },
            {
              "ID": "fd3bb585-13f5-4853-8605-bda9650b04da",
              "Code": "BatchDeleteCDO_DO_export_zhangbao1",
              "Name": "批量删除CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Void",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.2"
            },
            {
              "ID": "d3b5cdd8-f13b-485f-99a0-b69ae33fcc17",
              "Code": "BatchEditUpdateCDO_DO_export_zhangbao1",
              "Name": "批量编辑更新CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Void",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.3"
            },
            {
              "ID": "5ce683cf-2f4e-4678-9f39-04fb49800192",
              "Code": "BatchUpdateCDO_DO_export_zhangbao1",
              "Name": "批量更新CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Void",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.4"
            },
            {
              "ID": "68304738-b6ec-4237-8f52-f2922c00c855",
              "Code": "CreateCDO_DO_export_zhangbao1",
              "Name": "创建CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Void",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.5"
            },
            {
              "ID": "5a2b24f9-9abf-458a-b312-38380960d7d7",
              "Code": "DeleteCDO_DO_export_zhangbao1",
              "Name": "删除CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Void",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.6"
            },
            {
              "ID": "bdd07cee-c37e-4e2f-9b2e-8d338e5cfbc5",
              "Code": "GetCDO_DO_export_zhangbao1",
              "Name": "获取CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Record",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.7"
            },
            {
              "ID": "c1e505d0-893c-46c8-9995-7712f77f069d",
              "Code": "UpdateCDO_DO_export_zhangbao1",
              "Name": "更新CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "Action",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 0,
              "Icon": "icon-faslogic action",
              "TreeItemID": "Action",
              "DataResultType": "Void",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.8"
            },
            {
              "ID": "14e3f3f4-3e89-4b73-a7ec-bd3610168ec7",
              "Code": "GetCDO_DO_export_zhangbao1BasicList",
              "Name": "DQ_CDO_数据对象144933",
              "ParentID": "b13a5a03-0d44-4598-8f1d-7a57501d2f54",
              "TypeID": "",
              "Layer": 0,
              "IsDetail": false,
              "SortCode": 1,
              "Icon": "icon-fasdq dq",
              "TreeItemID": "DQ",
              "DataResultType": "",
              "MetaDataType": null,
              "Children": null,
              "seqNum": "1.1.9"
            }
          ],
          "VM": [
            {
              "ID": "dd077d3b-5a8d-49de-b365-f809e176d8b1",
              "DisplayName": ".ID",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.ID",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"ID\",\r\n  \"Text\": \"主键ID\",\r\n  \"DataType\": \"String\",\r\n  \"DBDataType\": \"Varchar\",\r\n  \"Length\": 36,\r\n  \"Precision\": 0,\r\n  \"IsNullable\": false,\r\n  \"IsPkColumn\": true,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "ID",
              "Name": "主键ID",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 9,
              "HelpInfo": ".ID",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 36,
                "AttrIsRequired": true,
                "AttrPrecision": 0,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": false,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "8a74b232-dd5d-45cf-bd73-d4dd5536d589",
              "DisplayName": ".Code",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.Code",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"Code\",\r\n  \"Text\": \"编号\",\r\n  \"DataType\": \"String\",\r\n  \"DBDataType\": \"Varchar\",\r\n  \"Length\": 128,\r\n  \"Precision\": 0,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "Code",
              "Name": "编号",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 9,
              "HelpInfo": ".Code",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 128,
                "AttrIsRequired": false,
                "AttrPrecision": 0,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": false,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "e53ce241-542d-47c7-9496-617c61bc2132",
              "DisplayName": ".Name",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.Name",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"Name\",\r\n  \"Text\": \"名称\",\r\n  \"DataType\": \"String\",\r\n  \"DBDataType\": \"Varchar\",\r\n  \"Length\": 128,\r\n  \"Precision\": 0,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "Name",
              "Name": "名称",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 9,
              "HelpInfo": ".Name",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 128,
                "AttrIsRequired": false,
                "AttrPrecision": 0,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": false,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "f9ac24d1-b0f6-413d-a104-88fc272a1018",
              "DisplayName": ".Creator",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.Creator",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"Creator\",\r\n  \"Text\": \"创建人\",\r\n  \"DataType\": \"String\",\r\n  \"DBDataType\": \"Varchar\",\r\n  \"Length\": 128,\r\n  \"Precision\": 0,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "Creator",
              "Name": "创建人",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 9,
              "HelpInfo": ".Creator",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 128,
                "AttrIsRequired": false,
                "AttrPrecision": 0,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": true,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "86a197b5-6461-4ff2-bc9d-a8bf45bd533b",
              "DisplayName": ".CreatorName",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.CreatorName",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"CreatorName\",\r\n  \"Text\": \"创建人姓名\",\r\n  \"DataType\": \"String\",\r\n  \"DBDataType\": \"Varchar\",\r\n  \"Length\": 128,\r\n  \"Precision\": 0,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "CreatorName",
              "Name": "创建人姓名",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 9,
              "HelpInfo": ".CreatorName",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 128,
                "AttrIsRequired": false,
                "AttrPrecision": 0,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": true,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "6e353d1a-352b-4e84-9ed8-1906067b8e95",
              "DisplayName": ".CreateTime",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.CreateTime",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"CreateTime\",\r\n  \"Text\": \"创建时间\",\r\n  \"DataType\": \"DateTime\",\r\n  \"DBDataType\": \"DateTime\",\r\n  \"Length\": 8,\r\n  \"Precision\": 3,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "CreateTime",
              "Name": "创建时间",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 5,
              "HelpInfo": ".CreateTime",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 8,
                "AttrIsRequired": false,
                "AttrPrecision": 3,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": true,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "eca920a5-8964-4806-9cb7-e6273d4e4cd3",
              "DisplayName": ".LastModifier",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.LastModifier",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"LastModifier\",\r\n  \"Text\": \"最后修改人\",\r\n  \"DataType\": \"String\",\r\n  \"DBDataType\": \"Varchar\",\r\n  \"Length\": 128,\r\n  \"Precision\": 0,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "LastModifier",
              "Name": "最后修改人",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 9,
              "HelpInfo": ".LastModifier",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 128,
                "AttrIsRequired": false,
                "AttrPrecision": 0,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": true,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "e9d25f8b-aa71-4478-838b-2a89ecdb35d7",
              "DisplayName": ".LastModifierName",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.LastModifierName",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"LastModifierName\",\r\n  \"Text\": \"最后修改人姓名\",\r\n  \"DataType\": \"String\",\r\n  \"DBDataType\": \"Varchar\",\r\n  \"Length\": 128,\r\n  \"Precision\": 0,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "LastModifierName",
              "Name": "最后修改人姓名",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 9,
              "HelpInfo": ".LastModifierName",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 128,
                "AttrIsRequired": false,
                "AttrPrecision": 0,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": false,
                "IsSystem": true,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            },
            {
              "ID": "f131f8c1-f587-4f02-9d76-1703d5308811",
              "DisplayName": ".LastModifyTime",
              "RefSchemaExpr": "Schema.DO.DO_export_zhangbao1.Columns.LastModifyTime",
              "RefSchemaExprValue": "{\r\n  \"Code\": \"LastModifyTime\",\r\n  \"Text\": \"最后修改时间\",\r\n  \"DataType\": \"Timestamp\",\r\n  \"DBDataType\": \"Timestamp\",\r\n  \"Length\": 8,\r\n  \"Precision\": 3,\r\n  \"IsNullable\": true,\r\n  \"IsPkColumn\": false,\r\n  \"IsFkColumn\": false,\r\n  \"RelatedDataObjectID\": null,\r\n  \"RelationType\": 0\r\n}",
              "Code": "LastModifyTime",
              "Name": "最后修改时间",
              "ItemType": 8,
              "DataResultType": null,
              "ValueType": 6,
              "HelpInfo": ".LastModifyTime",
              "ExprMetaDataID": "LocalVars",
              "ExprMetaDataAlias": null,
              "DataModels": null,
              "IsLeaf": true,
              "IsDelete": false,
              "ExprExt": {
                "AttrLength": 8,
                "AttrIsRequired": false,
                "AttrPrecision": 3,
                "AttrDefaultValue": null,
                "AttributeType": 0,
                "IsTimestamp": true,
                "IsSystem": true,
                "IsInternational": false,
                "IsEnableMasking": false,
                "IsEnableColumnPermission": false
              },
              "Children": [],
              "ExprFuncItemParamList": []
            }
          ]
        },
        "ShowValue": "CDO_数据对象144933"
      },
      "Columns": {
        "Value": [
          {
            "ColName": "ID",
            "ExcelColName": "主键ID",
            "caption": "主键ID",
            "DataSource": "",
            "DisplayField": "",
            "ValueField": "",
            "IsRequired": false,
            "isShow": true,
            "IsUnique": false,
            "IsHelp": false,
            "IsHelpReplace": false,
            "ImportRules": 0,
            "need": true,
            "ValueInfo_caption": {
              "ShowValue": "主键ID",
              "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.ID.Text",
              "Type": 0
            },
            "ValueInfo_ExcelColName": {
              "ShowValue": "主键ID",
              "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.ID.Text",
              "Type": 0
            }
          },
          {
            "ColName": "Code",
            "ExcelColName": "编号",
            "caption": "编号",
            "DataSource": "",
            "DisplayField": "",
            "ValueField": "",
            "IsRequired": false,
            "isShow": true,
            "IsUnique": false,
            "IsHelp": false,
            "IsHelpReplace": false,
            "ImportRules": 0,
            "need": true,
            "ValueInfo_caption": {
              "ShowValue": "编号",
              "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Code.Text",
              "Type": 0
            },
            "ValueInfo_ExcelColName": {
              "ShowValue": "编号",
              "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Code.Text",
              "Type": 0
            }
          },
          {
            "ColName": "Name",
            "ExcelColName": "名称",
            "caption": "名称",
            "DataSource": "",
            "DisplayField": "",
            "ValueField": "",
            "IsRequired": false,
            "isShow": true,
            "IsUnique": false,
            "IsHelp": false,
            "IsHelpReplace": false,
            "ImportRules": 0,
            "need": true,
            "ValueInfo_caption": {
              "ShowValue": "名称",
              "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Name.Text",
              "Type": 0
            },
            "ValueInfo_ExcelColName": {
              "ShowValue": "名称",
              "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Name.Text",
              "Type": 0
            }
          }
        ]
      },
      "MaxRows": 5000,
      "ImportStrategy": 1,
      "defineDataSocurce": [
        {
          "ColName": "ID",
          "ExcelColName": "主键ID",
          "caption": "主键ID",
          "DataSource": "",
          "DisplayField": "",
          "ValueField": "",
          "IsRequired": false,
          "isShow": true,
          "IsUnique": false,
          "IsHelp": false,
          "IsHelpReplace": false,
          "ImportRules": 0,
          "need": true,
          "ValueInfo_caption": {
            "ShowValue": "主键ID",
            "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.ID.Text",
            "Type": 0
          },
          "ValueInfo_ExcelColName": {
            "ShowValue": "主键ID",
            "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.ID.Text",
            "Type": 0
          }
        },
        {
          "ColName": "Code",
          "ExcelColName": "编号",
          "caption": "编号",
          "DataSource": "",
          "DisplayField": "",
          "ValueField": "",
          "IsRequired": false,
          "isShow": true,
          "IsUnique": false,
          "IsHelp": false,
          "IsHelpReplace": false,
          "ImportRules": 0,
          "need": true,
          "ValueInfo_caption": {
            "ShowValue": "编号",
            "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Code.Text",
            "Type": 0
          },
          "ValueInfo_ExcelColName": {
            "ShowValue": "编号",
            "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Code.Text",
            "Type": 0
          }
        },
        {
          "ColName": "Name",
          "ExcelColName": "名称",
          "caption": "名称",
          "DataSource": "",
          "DisplayField": "",
          "ValueField": "",
          "IsRequired": false,
          "isShow": true,
          "IsUnique": false,
          "IsHelp": false,
          "IsHelpReplace": false,
          "ImportRules": 0,
          "need": true,
          "ValueInfo_caption": {
            "ShowValue": "名称",
            "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Name.Text",
            "Type": 0
          },
          "ValueInfo_ExcelColName": {
            "ShowValue": "名称",
            "ReferenceExpr": "Schema.DO.DO_export_zhangbao1.Columns.Name.Text",
            "Type": 0
          }
        }
      ]
    }`;
  // 元数据 - 导入高级设置
  const importConfig = ref(JSON.parse(stringImportConfig));
  // 元数据 - 导出高级设置
  const exportConfig = reactive({});

  // 测试方法
  const handleFather = () => {
    console.log('imEx.value', imEx.value);
    alert(1);
  };

  // 导入的方法
  const handleImport = () => {
    console.log('----- father import');
    imEx.value.upload.click();
  };
  const getBase64 = file => {
    return new Promise((resolve, reject) => {
      ///FileReader类就是专门用来读文件的
      const reader = new FileReader();
      //开始读文件
      //readAsDataURL: dataurl它的本质就是图片的二进制数据， 进行base64加密后形成的一个字符串，
      reader.readAsDataURL(file);
      // 成功和失败返回对应的信息，reader.result一个base64，可以直接使用
      reader.onload = () => resolve(reader.result);
      // 失败返回失败的信息
      reader.onerror = error => reject(error);
    });
  };
  // 读取cookie
  const getCookie = c_name => {
    if (document.cookie.length > 0) {
      var c_start = document.cookie.indexOf(c_name + '=');
      if (c_start != -1) {
        c_start = c_start + c_name.length + 1;
        var c_end = document.cookie.indexOf(';', c_start);
        if (c_end == -1) c_end = document.cookie.length;
        return unescape(document.cookie.substring(c_start, c_end));
      }
    }
    return '';
  };
  // 导入 - 选中-确认-读取文件后
  const importConfirmation = (url, name, val) => {
    console.log('url, name, val,', url, name, val);
    uploadUrl.value = url;
    uploadName.value = name;
    let importDefs = [];
    if (importConfig.defineDataSocurce) {
      let defineDataSocurce = JSON.parse(
        JSON.stringify(importConfig.defineDataSocurce),
      );
      importDefs = defineDataSocurce.filter(item => {
        item.ImportRule = item.ImportRules;
        if (item.Parameters) {
          item.Parameters.map(j => {
            if (j.ParameterValue) {
              j.ParameterValue = window.TeldFasRTUtils.expression.execute(
                j.ParameterValue,
              ).result;
              console.log('执行了脚本编辑器======================');
              console.log(
                window.TeldFasRTUtils.expression.execute(j.ParameterValue)
                  .result,
              );
            }
            return j;
          });
        }
        return item.isShow || item.ImportRules == 2;
      });
    }
    window.getDataAsync(
      // fasRequestTagAdd 也是挂在 运行时 window 上的 function
      fasRequestTagAdd(window.FrameSGHost + 'FASR-ImportConfirm'),
      'POST',
      {
        fileURL: url,
        importDefs: JSON.stringify(importDefs),
        isEnableUniqueCol: importConfig.hasOwnProperty('IsEnableUniqueCol')
          ? importConfig.IsEnableUniqueCol
          : true,
        isEnableExplainRow: importConfig.hasOwnProperty('IsEnableExplainRow')
          ? importConfig.IsEnableExplainRow
          : true,
      },
      function (data) {
        // 一个 response 的 demo
        // {
        //   "state": "1",
        //   "sheets": [
        //       {
        //           "SheetName": "Sheet0",
        //           "RowNum": 2
        //       },
        //       {
        //           "SheetName": "Sheet1",
        //           "RowNum": 1
        //       }
        //   ]
        // }
        // 等待改造
        if (data.state == 1) {
          dialogVisibleTip.value = false;
          nextTick(() => {
            sheetList = data.sheets;
            sheetName.value = data.sheets[0].SheetName;
            self.RowNum = data.sheets[0].RowNum;
            self.importFlag = val;
            if (sheetList.length != 1) {
              dialogVisibleTip.value = true;
            } else {
              self.importData(url, name);
            }
          });
        } else {
          // Funcs.Notify(
          //   Terms.title.notify,
          //   `${Terms.notify.failReason}：${data.errmsg}`,
          //   'warning',
          // );
          imEx.value.$q.notify({
            closeBtn: true,
            type: 'warning',
            position: 'bottom-right',
            message: `失败原因：${data.errmsg}`,
          });
        }
      },
      function () {},
    );
  };
  // 导入文件获取到
  const getImportFile = async (e, val, data) => {
    debugger;
    console.log('father', e);
    // 第一部分 - 制作数据
    retryJson.value = data;
    // 导入事件
    let file = e.target.files[0];
    let realfile = await getBase64(file);
    realfile = realfile.split(',')[1];
    let params = {
      Data: realfile,
      Extension: file.name.split('.').pop(),
      Name: file.name,
      PathId: '101',
    };
    // 第二部分 - 调用请求
    var xhr = new XMLHttpRequest();
    // 请求地址 demo
    // http: + //resource.teld.cc + /api/resource/uploaddoc
    // window.ResourcePath => window.TeldWebConfig.ResourceURL
    xhr.open(
      'POST',
      window.location.protocol +
        window.TeldWebConfig.ResourceURL +
        '/api/resource/uploaddoc',
      false,
    );
    // 添加http头，发送信息至服务器时内容编码类型
    xhr.setRequestHeader('X-Token', getCookie('telda'));
    xhr.setRequestHeader('SRC', 'WEB');
    xhr.setRequestHeader('Content-Type', 'application/json');
    xhr.onreadystatechange = async () => {
      debugger;
      if (xhr.readyState == 4) {
        if (xhr.status == 200 || xhr.status == 304) {
          console.log(xhr.responseText);
          var response;
          if (typeof xhr.responseText == 'string') {
            try {
              response = JSON.parse(xhr.responseText);
              console.log(response);
            } catch (error) {
              console.log(error);
              response = {};
            }
          } else {
            response = xhr.responseText;
          }
          importConfirmation(response.RelativeUrl, file.name, val);
        } else if (xhr.status == 401) {
        } else {
          // flag - 删除这个 else , 暂时为了看效果的
          console.log('404');
          // importConfirmation('url', file.name, val);
        }
      }
      uplaodFile.value = false;
      nextTick(() => {
        uplaodFile.value = true;
      });
    };
    xhr.send(JSON.stringify(params));
    // console.log(params);
  };
  const handleExport = () => {
    // 单独设置 - 穿梭数据 - to 张辰 demo
    dialogEx.value = true;
    console.log('----- father export');
  };
  //

  const checkCdo = () => {
    // 语法优化
    // if (!importConfig.CdoSource.Value && !importConfig.CdoSource.Value.ID) {
    if (!importConfig?.CdoSource?.Value?.ID) {
      // Funcs.Notify(Terms.title.notify, Terms.title.checkCdo, 'warning');
      imEx.value.$q.notify({
        closeBtn: true,
        type: 'warning',
        position: 'bottom-right',
        message: '导入控件配置不完整，请选择CDO',
      });
      return false;
    }
    return true;
    // 导入导出控件配置不完整，请选择cdo、DQ
  };
  // dataURLtoBlob + downloadFile + downloadFileByBase64 + dowmloadTemplate
  const dataURLtoBlob = dataurl => {
    var arr = dataurl.split(','),
      mime = arr[0].match(/:(.*?);/)[1],
      // atob 运行时全局的方法
      bstr = atob(arr[1]),
      n = bstr.length,
      u8arr = new Uint8Array(n);
    while (n--) {
      u8arr[n] = bstr.charCodeAt(n);
    }
    return new Blob([u8arr], { type: mime });
  };
  const downloadFile = (url, name) => {
    var a = document.createElement('a');
    a.setAttribute('href', url);
    a.setAttribute('download', name);
    a.setAttribute('target', '_blank');
    let clickEvent = document.createEvent('MouseEvents');
    clickEvent.initEvent('click', true, true);
    a.dispatchEvent(clickEvent);
  };
  const downloadFileByBase64 = (base64, name) => {
    var myBlob = dataURLtoBlob(base64);
    // URL 运行时全局的方法
    var myUrl = URL.createObjectURL(myBlob);
    downloadFile(myUrl, name);
  };
  const dowmloadTemplate = () => {
    console.log(importConfig, 'importConfig');
    if (!checkCdo()) {
      return;
    }
    let importDefs = [];
    console.log(importConfig, 'importConfig');
    if (importConfig.defineDataSocurce) {
      let defineDataSocurce = JSON.parse(
        JSON.stringify(importConfig.defineDataSocurce),
      );
      importDefs = defineDataSocurce.filter(item => {
        item.ImportRule = item.ImportRules;
        if (item.Parameters) {
          item.Parameters.map(j => {
            if (j.ParameterValue) {
              j.ParameterValue = window.TeldFasRTUtils.expression.execute(
                j.ParameterValue,
              ).result;
              console.log('执行了脚本编辑器======================');
              console.log(
                window.TeldFasRTUtils.expression.execute(j.ParameterValue)
                  .result,
              );
            }
            return j;
          });
        }
        return item.isShow;
      });
    }
    window.getDataAsync(
      fasRequestTagAdd(window.FrameSGHost + 'FASR-DownloadTemplate'),
      'POST',
      {
        cdoID: importConfig.CdoSource.Value.ID,
        importDefs: JSON.stringify(importDefs),
        isEnableUniqueCol: importConfig.hasOwnProperty('IsEnableUniqueCol')
          ? importConfig.IsEnableUniqueCol
          : true,
        isEnableExplainRow: importConfig.hasOwnProperty('IsEnableExplainRow')
          ? importConfig.IsEnableExplainRow
          : true,
      },
      function (data) {
        if (data.state == 1) {
          downloadFileByBase64(data.content, data.fileName);
        } else {
          // Funcs.Notify(
          //   Terms.title.notify,
          //   `${Terms.notify.failReason}：${data.errmsg}`,
          //   'warning',
          // );
          imEx.value.$q.notify({
            closeBtn: true,
            type: 'warning',
            position: 'bottom-right',
            message: `失败原因：${data.errmsg}`,
          });
        }
      },
      function () {},
    );
  };

  // 按钮名称为：导入模板 / 下载模板
  const downloadStencil = () => {
    console.log('----- father downloadStencil');
    dowmloadTemplate();
  };
  // 点击任务列表 btn
  const handleMissionList = () => {
    GetImportTaskList();
    console.log('----- father handleMissionList');
  };

  // 展示任务列表导入导出数据
  const GetImportTaskList = () => {
    dialog.value = true;
    pageSize.value = 10;
    pageIndex.value = 1;
    getTaskList();
  };

  // 获取任务列表导入导出数据
  const getTaskList = async isRefresh => {
    if (tab.value === 0) {
      // 获取导入任务列表
      await refreshGetImportTaskList();
    } else if (tab.value === 1) {
      // 获取导出任务列表
      alert('导出任务列表');
      // await this.refreshGetExportTaskList();
      // ...
    }
    if (isRefresh) {
      // Funcs.Notify(Terms.title.notify, Terms.title.refreshSuccess, 'success');
      imEx.value.$q.notify({
        closeBtn: true,
        type: 'success',
        position: 'bottom-right',
        message: `数据刷新成功`,
      });
    }
  };
  // 获取导入任务列表
  // const refreshGetImportTaskList = () => {}
  const refreshGetImportTaskList = () => {
    if (!checkCdo()) {
      return;
    }
    TFF.common.ajax
      .getDataAsync({
        url: Funcs.FasRequestTagAdd(
          TFF.common.ajax.getServiceUrl('FASR-GetImportTaskList'),
        ),
        type: 'post',
        data: {
          cdoID: importConfig.CdoSource.Value.ID,
          filter: JSON.stringify({
            pageSize: pageSize.value,
            pageIndex: pageIndex.value,
          }),
        },
      })
      .then(data => {
        if (data.state == 1) {
          // rowsIm ~ 老的 ImportTasklist
          rowsIm = data.data;
          rowsIm = rowsIm.slice(0);
          totalCount.value = data.total;
        } else {
          imEx.value.$q.notify({
            closeBtn: true,
            type: 'warning',
            position: 'bottom-right',
            message: `失败原因：${data.errmsg}`,
          });
        }
      });
    // 迁移前，老的写法
    // window.getDataAsync(
    //   fasRequestTagAdd(window.FrameSGHost + 'FASR-GetImportTaskList'),
    //   'POST',
    //   {
    //     cdoID: importConfig.CdoSource.Value.ID,
    //     filter: JSON.stringify({
    //       pageSize: pageSize.value,
    //       pageIndex: pageIndex.value,
    //     }),
    //   },
    //   function (data) {
    //     if (data.state == 1) {
    //       // rowsIm ~ 老的 ImportTasklist
    //       rowsIm = data.data;
    //       rowsIm = rowsIm.slice(0);
    //       totalCount.value = data.total;
    //     } else {
    //       imEx.value.$q.notify({
    //         closeBtn: true,
    //         type: 'warning',
    //         position: 'bottom-right',
    //         message: `失败原因：${data.errmsg}`,
    //       });
    //     }
    //   },
    //   function () {
    //     //console.log(data)
    //   },
    // );
  };
  const tautology = e => {
    //
    if (e.target.querySelector('input')) {
      e.target.querySelector('input').click();
    }
  };
  // importData + downloadExcel
  const importData = (url, fileName) => {
    let self = this;
    if (
      this.findEventByName('BeforeImport') &&
      this.findEventByName('BeforeImport').ActionType != -1
    ) {
      try {
        // window.Widget.fas_import_and_export163430
        this.triggerEventHandler('BeforeImport', arguments);
      } catch (err) {
        Funcs.Notify(Terms.title.notify, err.message, 'warning');
        // self.$message({
        //   message: err.message,
        //   type: "warning",
        //   showClose: true,
        // });
      }
      let instanceCode = this.options.instanceCode;
      let JSScript = this.findEventByName('BeforeImport').JSScript;
      let hasFunction = true;
      let isNot = false;
      if (JSScript.indexOf('.' + instanceCode + '.import') != -1) {
        let JSScriptArr = JSScript.split('\n');
        JSScriptArr.forEach(item => {
          if (item.indexOf('.' + instanceCode + '.import') != -1) {
            let Params = item.split(';');
            console.log(Params);
            let index = Params.findIndex(
              item => item.indexOf('.' + instanceCode + '.import') != -1,
            );
            console.log(index);
            if (
              Params[index] &&
              !(
                Params[index].indexOf('*') == -1 &&
                Params[index].indexOf('//') == -1
              )
            ) {
              hasFunction = false;
            } else {
              isNot = true;
            }
          }
        });
      } else {
        hasFunction = false;
      }
      if (hasFunction || isNot) {
      } else {
        this.import(url, fileName);
      }
    } else {
      this.import(url, fileName);
    }
  };

  const fileToBase64 = (fileUrl, name) => {
    let self = this;
    var xhr = new XMLHttpRequest();
    xhr.open('GET', fileUrl, true);
    xhr.responseType = 'blob';
    xhr.onload = function () {
      if (this.status === 200) {
        var blob = this.response;
        if (window.FileReader) {
          var reader = new FileReader();
          reader.onloadend = function () {
            var base64Data = reader.result;
            self.downloadFileByBase64(base64Data, name);
            console.log(base64Data);
          };
          reader.readAsDataURL(blob);
        } else {
          var myUrl = URL.createObjectURL(blob);
          self.downloadFile(myUrl, name);
          // self.downloadFileByBase64(blob, name)
        }
      }
    };
    xhr.send();
  };
  const downloadExcel = (data, val) => {
    if (val == 'retry') {
      if (data.row.FileURL) {
        importData(data.row.FileURL, data.row.FileName);
      }
    } else {
      if (data.row.FileURL) {
        // window.ResourcePath => window.TeldWebConfig.ResourceURL
        this.fileToBase64(
          window.TeldWebConfig.ResourceURL + '/' + data.row.FileURL,
          data.row.FileName,
        );
      }
    }
  };
  // GoPage + deleteLine
  const GoPage = pageIndex => {
    if (pageIndex >= 1 && totalCount.value > 0) {
      if (pageIndex <= Math.ceil(totalCount.value / pageSize.value)) {
        pageIndex.value = pageIndex;
        console.log(pageIndex.value, 'pageIndex.value');
      } else {
        pageIndex.value = Math.ceil(totalCount.value / pageSize.value);
      }
    } else {
      pageIndex.value = 1;
    }
    getTaskList();
  };
  // 任务列表 - 导入任务 - table 数据 - 行btn 删除
  const deleteLine = data => {
    console.log('deleteLine data', data);
    TFF.common.ajax
      .getDataAsync({
        url: Funcs.FasRequestTagAdd(
          TFF.common.ajax.getServiceUrl('FASR-DeleteImportTask'),
        ),
        type: 'post',
        data: {
          taskID: data.data.ID,
        },
      })
      .then(data => {
        if (data.state) {
          if (data.state == 1) {
            totalCount.value--;
            GoPage(this.pageIndex);
          } else {
            imEx.value.$q.notify({
              closeBtn: true,
              type: 'warning',
              position: 'bottom-right',
              message: `失败原因：${data.errmsg}`,
            });
          }
        }
      });

    // let self = this;
    // window.getDataAsync(
    //   fasRequestTagAdd(window.FrameSGHost + 'FASR-DeleteImportTask'),
    //   'POST',
    //   {
    //     taskID: data.data.ID,
    //   },
    //   data => {
    //     if (data.state) {
    //       if (data.state == 1) {
    //         // this.getTaskList();
    //         this.totalCount--;
    //         this.GoPage(this.pageIndex);
    //       } else {
    //         Funcs.Notify(Terms.title.notify, data.errmsg, 'warning');
    //       }
    //     }
    //   },
    //   function () {
    //     //console.log(data)
    //   },
    // );
  };

  // methods
</script>
